package com.peter.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.peter.api.common.ErrorCode;
import com.peter.api.exception.BusinessException;
import com.peter.api.exception.ThrowUtils;
import com.peter.api.mapper.InterfaceInfoMapper;
import com.peter.api.model.dto.interfaceInfoDTO.InterfaceInfoQueryRequest;
import com.peter.api.model.entity.InterfaceInfo;
import com.peter.api.model.entity.Post;
import com.peter.api.model.vo.InterfaceInfoVO;
import com.peter.api.service.InterfaceInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
* @author 李皮特
* @description 针对表【interface_info(接口信息)】的数据库操作Service实现
* @createDate 2024-11-05 23:27:22
*/
@Service
public class InterfaceInfoServiceImpl extends ServiceImpl<InterfaceInfoMapper, InterfaceInfo>
    implements InterfaceInfoService {

    @Override
    public void validInterfaceInfo(InterfaceInfo post, boolean add) {
        if (post == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        String name = post.getName();
        String description = post.getDescription();
        String url = post.getUrl();
        String requestHeader = post.getRequestHeader();
        String responseHeader = post.getResponseHeader();
        String method = post.getMethod();
        // 创建时，参数不能为空
        if (add) {
            ThrowUtils.throwIf(StringUtils.isAnyBlank(name, description, url,requestHeader,responseHeader,method), ErrorCode.PARAMS_ERROR);
        }
        // 有参数则校验
        if (StringUtils.isNotBlank(name) && name.length() > 80) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "标题过长");
        }
        if (StringUtils.isNotBlank(description) && description.length() > 8192) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "内容过长");
        }
    }



    @Override
    public QueryWrapper<InterfaceInfo> getQueryWrapper(InterfaceInfoQueryRequest postQueryRequest) {
        return null;
    }

    @Override
    public InterfaceInfoVO getInterfaceInfoVO(InterfaceInfo post, HttpServletRequest request) {
        return null;
    }

    @Override
    public Page<InterfaceInfoVO> getInterfaceInfoVOPage(Page<InterfaceInfo> postPage, HttpServletRequest request) {
        return null;
    }
}




